package com.example.zx_springboot.controller;

import com.example.zx_springboot.entity.ZxRole;
import com.example.zx_springboot.entity.Zxicon;
import com.example.zx_springboot.service.ZxRoleService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ZxRoleController {
    @Autowired
    private ZxRoleService zxRoleService;
    @GetMapping("/rolefindpage")
    public PageInfo findlossAll(@RequestParam("pageNum") Integer pageNum,
                                @RequestParam("pageSize") Integer pageSize,
                                @RequestParam("role_name") String role_name) {
        return zxRoleService.rolefindByPage(pageNum, pageSize,role_name);
    }
    @PostMapping("/updaterole")
    public String updaterole(@RequestBody ZxRole zxRole){
        zxRoleService.updaterole(zxRole);
        return "update success";

    }
    @DeleteMapping("/deleterole")
    public  String deleterole(@RequestParam("role_id") Integer role_id){
        zxRoleService.deleterole(role_id);
        return "delete success";
    }
    @PostMapping("/deleteroles")
    public  String deleteroles(@RequestBody List<Integer> ids){
        zxRoleService.deleteroles(ids);
        return "delete success";
    }
    @PostMapping("/addrole")
    public String addrole(@RequestBody ZxRole zxRole){
        zxRoleService.addrole(zxRole);

        return "add success";
    }
    @PostMapping("/savemens/{role_id}")
    public String savemenus(@PathVariable Integer role_id, @RequestBody List<Integer> menuids){
        zxRoleService.savemenus(role_id,menuids);
        return "savemenus success";
    }
    @GetMapping("/exitmenus/{role_id}")
    public List<Integer> exitmenus(@PathVariable Integer role_id){
        return zxRoleService.exitmenus(role_id);
    }
    @GetMapping("/icons")
    public List<Zxicon> geticon(){
       return zxRoleService.geticon();
    }
}
